using Microsoft.AspNetCore.Http;
using XjjXmm.Infrastructure.User;

namespace xjjxmm.infrastructure.Webs;


public class ThreadLocalContext
{
    private readonly IHttpContextAccessor _contextAccessor;

    public ThreadLocalContext(IHttpContextAccessor contextAccessor)
    {
        _contextAccessor = contextAccessor;
    }

    public  void Set(string key, dynamic obj)
    {
        _contextAccessor.HttpContext?.Items.Add(key, obj);
       
    }

    public T? Get<T>(string key)
    {
        return (T?)_contextAccessor.HttpContext?.Items[key];
    }

    public void Clear()
    {
        _contextAccessor.HttpContext?.Items.Clear();
    }
    
    
}

